function clearRegistrationForm() {
    dijit.byId("regUserName").reset();
    dijit.byId("regPassword").reset();
    dijit.byId("regEmail").reset();
    dojo.byId("registrationValidation").innerHTML="";
}

function validateRegistrationForm(error) {
    dojo.byId("registrationValidation").innerHTML = "";
    if ((!dijit.byId("regUserName").isValid()) || (!dijit.byId("regPassword").isValid()) || (!dijit.byId("regEmail").isValid())) {
        dojo.byId("registrationValidation").innerHTML = "<span><img style='height:20px;vertical-align:middle;padding-right:3px' src='" + contextPath + "/resource.iwebmvc?file=/images/cancelupload_soria.png" + sessionQueryPath + "' alt='Error' />" + error + "</span>";
        return;
    }
    TrackerUserManager.register(dijit.byId("regUserName").getValue(),
        dijit.byId("regPassword").getValue(),
        dijit.byId("regEmail").getValue(),
        function(data) {
            if (!data) {
                closePopup("registrationform");
            } else {
                dojo.byId("registrationValidation").innerHTML = "<span><img style='height:20px;vertical-align:middle;padding-right:3px' src='" + contextPath + "/resource.iwebmvc?file=/images/cancelupload_soria.png" + sessionQueryPath + "' alt='Error' />" + data + "</span>";
            }
        }
    );
}

function changeProfilePassword(error) {
    dojo.byId("profileSecurityValidation").innerHTML = "";
    if (!dijit.byId("profilePassword").isValid()) {
        dojo.byId("profileSecurityValidation").innerHTML = "<span><img style='height:20px;vertical-align:middle;padding-right:3px' src='" + contextPath + "/resource.iwebmvc?file=/images/cancelupload_soria.png" + sessionQueryPath + "' alt='Error' />" + error + "</span>";
    }
    TrackerUserManager.changePassword(dijit.byId("profilePassword").getValue(), function(data) {
        if (!data) {
            closePopup("editprofileform");
        } else {
            dojo.byId("profileSecurityValidation").innerHTML = "<span><img style='height:20px;vertical-align:middle;padding-right:3px' src='" + contextPath + "/resource.iwebmvc?file=/images/cancelupload_soria.png" + sessionQueryPath + "' alt='Error' />" + data + "</span>";
        }
    });
}

function saveOfflineData() {
    var sex = DomainEntitySex.items[dijit.byId("sexprofile").getValue()].id;
    TrackerUserManager.editOfflineInformation(dijit.byId("profileName").getValue(), dojo.isArray(sex) ? sex[0] : sex, dojo.byId("location").value);
    closePopup("editprofileform");
}

function savePreferencesData(error) {
    if ((!dijit.byId("profileEmail").isValid()) || (!dijit.byId("languageSelector").isValid()) || (!dijit.byId("themeSelector").isValid())) {
        dojo.byId("profilePreferencesValidation").innerHTML = "<span><img style='height:20px;vertical-align:middle;padding-right:3px' src='" + contextPath + "/resource.iwebmvc?file=/images/cancelupload_soria.png" + sessionQueryPath + "' alt='Error' />" + error + "</span>";
        return;
    }
    TrackerUserManager.editPreferences(dijit.byId("profileEmail").getValue(), dijit.byId("themeSelector").getValue(), dijit.byId("languageSelector").getValue(), function() {
        closePopup("editprofileform");
        window.location.reload(true);
    });
}

function clearProfileForm() {
    dijit.byId("profilePassword").reset();
    dojo.byId("profileSecurityValidation").innerHTML = "";
    dojo.byId("profilePreferencesValidation").innerHTML = "";
    dijit.byId("editProfileTabContainer").resize();
}